/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package servlets;

import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 *
 * @author sebkas
 */
public class reservar extends HttpServlet {

    /**
     * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {

        String action = request.getParameter("action");
        HttpSession session = request.getSession();

        if(action==null){
            session.setAttribute("error", "Lo sentimos. Ha ocurrido un error procesando la solicitud.");
            response.sendRedirect("error.jsp");
        }else if(action.equals("reservar")){
            java.util.List<DTOs.DTOAerolinea> dtoa = new java.util.ArrayList<DTOs.DTOAerolinea>();
            try{
                dtoa = (java.util.List<DTOs.DTOAerolinea>) session.getAttribute("DTOA");
            }catch(Exception e){
                dtoa = new java.util.ArrayList<DTOs.DTOAerolinea>();
            }
            java.util.List<DTOs.DTOHotel> dtoh = new java.util.ArrayList<DTOs.DTOHotel>();
            try{
                dtoh = (java.util.List<DTOs.DTOHotel>) session.getAttribute("DTOH");
            }catch(Exception e){
                dtoh = new java.util.ArrayList<DTOs.DTOHotel>();
            }
            java.util.List<DTOs.DTORestaurante> dtor = new java.util.ArrayList<DTOs.DTORestaurante>();
            try{
                dtor = (java.util.List<DTOs.DTORestaurante>) session.getAttribute("DTOR");
            }catch(Exception e){
                dtor = new java.util.ArrayList<DTOs.DTORestaurante>();
            }
            java.util.List<DTOs.DTOTeatros> dtot = new java.util.ArrayList<DTOs.DTOTeatros>();
            try{
                dtot = (java.util.List<DTOs.DTOTeatros>) session.getAttribute("DTOT");
            }catch(Exception e){
                dtot = new java.util.ArrayList<DTOs.DTOTeatros>();
            }
            String username =(String) session.getAttribute("username");

            String message = (String)request.getAttribute("message");
            if(username == null){username = "";}
            if (message == null){message = "";}
            if(dtoa == null){
                dtoa = new java.util.ArrayList<DTOs.DTOAerolinea>();
            }
            if(dtoh == null){
                dtoh = new java.util.ArrayList<DTOs.DTOHotel>();
            }
            if(dtor == null){
                dtor = new java.util.ArrayList<DTOs.DTORestaurante>();
            }
            if(dtot == null){
                dtot = new java.util.ArrayList<DTOs.DTOTeatros>();
            }
            businessDelegate.BusinessDelegate bd = new businessDelegate.BusinessDelegate();
            boolean succes = bd.reservar(username,dtoa,dtoh,dtor,dtot);
        }
    }

    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    /**
     * Handles the HTTP <code>GET</code> method.
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        processRequest(request, response);
    }

    /**
     * Handles the HTTP <code>POST</code> method.
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        processRequest(request, response);
    }

    /**
     * Returns a short description of the servlet.
     * @return a String containing servlet description
     */
    @Override
    public String getServletInfo() {
        return "Short description";
    }// </editor-fold>

}